home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / msghook / systray.frm (.txt) < prev    next >
Visual Basic Form  |  1999-02-22  |  5KB  |  167 lines

  1. VERSION 4.00
  2. Begin VB.Form frmSysTray 
  3.    BorderStyle     =   4  'Fixed ToolWindow
  4.    Caption         =   "SysTray"
  5.    ClientHeight    =   2385
  6.    ClientLeft      =   2820
  7.    ClientTop       =   3555
  8.    ClientWidth     =   4110
  9.    Height          =   2790
  10.    Icon            =   "SysTray.frx":0000
  11.    Left            =   2760
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   2385
  16.    ScaleWidth      =   4110
  17.    ShowInTaskbar   =   0   'False
  18.    Top             =   3210
  19.    Width           =   4230
  20.    Begin MSGHOOKLibCtl.MsgHook MsgHook1 
  21.       Left            =   120
  22.       OleObjectBlob   =   "SysTray.frx":014A
  23.       Top             =   1740
  24.    End
  25.    Begin VB.Label Label2 
  26.       BackStyle       =   0  'Transparent
  27.       Caption         =   "Copyright 
  28.  1998, Alex Wainstein"
  29.       Height          =   240
  30.       Left            =   60
  31.       TabIndex        =   3
  32.       Top             =   810
  33.       Width           =   3210
  34.    End
  35.    Begin VB.Label lblMailTo 
  36.       BackStyle       =   0  'Transparent
  37.       Caption         =   "AlexW@Amdocs.com"
  38.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  39.          Name            =   "Lucida Sans Unicode"
  40.          Size            =   8.25
  41.          Charset         =   177
  42.          Weight          =   400
  43.          Underline       =   -1  'True
  44.          Italic          =   0   'False
  45.          Strikethrough   =   0   'False
  46.       EndProperty
  47.       ForeColor       =   &H8000000D&
  48.       Height          =   240
  49.       Left            =   645
  50.       MouseIcon       =   "SysTray.frx":0170
  51.       MousePointer    =   99  'Custom
  52.       TabIndex        =   2
  53.       Top             =   1080
  54.       Width           =   1875
  55.    End
  56.    Begin VB.Label Label4 
  57.       BackStyle       =   0  'Transparent
  58.       Caption         =   "e-mail:"
  59.       Height          =   210
  60.       Left            =   75
  61.       TabIndex        =   1
  62.       Top             =   1080
  63.       Width           =   510
  64.    End
  65.    Begin VB.Label Label1 
  66.       Caption         =   "This sample uses Message Hook control to create a taskbar tray notification area icon and handle all mouse events."
  67.       Height          =   675
  68.       Left            =   90
  69.       TabIndex        =   0
  70.       Top             =   90
  71.       Width           =   3945
  72.    End
  73.    Begin VB.Menu mnuBar 
  74.       Caption         =   "Menu"
  75.       Visible         =   0   'False
  76.       Begin VB.Menu mnuShow 
  77.          Caption         =   "&Show"
  78.       End
  79.       Begin VB.Menu mnuExit 
  80.          Caption         =   "E&xit"
  81.       End
  82.       Begin VB.Menu mnuSep1 
  83.          Caption         =   "-"
  84.       End
  85.       Begin VB.Menu mnuAbout 
  86.          Caption         =   "&About"
  87.       End
  88.    End
  89. Attribute VB_Name = "frmSysTray"
  90. Attribute VB_Creatable = False
  91. Attribute VB_Exposed = False
  92. Option Explicit
  93. ' See Global.bas for the global declarations
  94. Dim t As NOTIFYICONDATA
  95. Private bExit As Boolean
  96. Private Sub Form_Load()
  97. '1. Add icon to the system tray
  98.     t.cbSize = Len(t)
  99.     t.hwnd = Me.hwnd
  100.     t.uId = 1&
  101.     t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
  102.     t.ucallbackMessage = WM_TRAYNOTIFY
  103.     t.hIcon = Me.Icon
  104.     t.szTip = "Message Hook!" & Chr$(0)
  105.     Shell_NotifyIcon NIM_ADD, t
  106.     App.TaskVisible = False
  107. '2. Set MsgHook to handle WM_TRAYNOTIFY message for this window
  108. MsgHook1.hwnd = hwnd
  109. MsgHook1.AddMessage WM_TRAYNOTIFY, mshEatMessage 'mshPostProcess
  110. End Sub
  111. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  112. ' If closed from system menu or 'x' button - just hide
  113. If UnloadMode = vbFormControlMenu And Not bExit Then
  114.     Cancel = True
  115.     Hide
  116. End If
  117. 'else close
  118. End Sub
  119. Private Sub Form_Unload(Cancel As Integer)
  120.     t.cbSize = Len(t)
  121.     t.hwnd = Me.hwnd
  122.     t.uId = 1&
  123.     t.uFlags = 0&
  124.     Shell_NotifyIcon NIM_DELETE, t
  125. End Sub
  126. Private Sub lblMailTo_Click()
  127. Dim res As Long
  128. Dim lpOperation As String
  129. Dim lpFile As String
  130. Dim lpParameters As String
  131. Dim lpDirectory As String
  132. Dim nShowCmd As Long
  133. lpOperation = "open"
  134. lpFile = "MAILTO:" + lblMailTo
  135. nShowCmd = vbNormalFocus
  136. res = ShellExecute(hwnd, lpOperation, lpFile, lpParameters, ByVal lpDirectory, nShowCmd)
  137. End Sub
  138. Private Sub mnuAbout_Click()
  139.     frmAbout.Show vbModal
  140. End Sub
  141. Private Sub mnuExit_Click()
  142. ' We cannot simply call Unload Me because we need
  143. ' to let Message Hook to complete window message processing
  144. ' BEFORE the window is destroyed, but Unload Me does SendMessage
  145. ' We need to use PostMessage:
  146. bExit = True
  147. PostMessage MsgHook1.hwnd, WM_CLOSE, 0&, 0&
  148. End Sub
  149. Private Sub mnuShow_Click()
  150.     Me.Show
  151. End Sub
  152. Private Sub MsgHook1_Message(ByVal MsgId As Long, ByVal wParam As Long, ByVal lParam As Long, ByVal MsgProcessing As Integer, MsgResult As Long)
  153. Select Case MsgId
  154. Case WM_TRAYNOTIFY:
  155.        Select Case lParam
  156.             Case WM_LBUTTONDBLCLK:
  157.             Case WM_LBUTTONDOWN:
  158.             Case WM_LBUTTONUP:
  159.                     mnuShow_Click
  160.             Case WM_RBUTTONDBLCLK:
  161.             Case WM_RBUTTONDOWN:
  162.             Case WM_RBUTTONUP:
  163.                 PopupMenu mnuBar, , , , mnuShow ' This may invoke mnuExit_Click
  164.         End Select
  165. End Select
  166. End Sub
  167.